package com.jeff

import org.codehaus.groovy.grails.web.metaclass.WithFormMethod;

import grails.converters.*

class AirportController {

    def index = { }
	
	def debugAccept = {
		def clientType = request.getHeader("accept")
		def serverType = request.format
		render "Client: $clientType\nServer: $serverType\n"
//		def result = new Airport(name:"Changi SG",code:"SG")
//		render result as JSON
	}
	
	//in current version of grails/curl, "--header accept:text/xml" becomes no effect, whereas "?format=xml" still work
	def listMe = {
		def result = new Airport(name:"Changi SG",code:"SG")
		withFormat {
			html{
				render "Airport: ${result.name}\n"
			}
			xml{
				render result as XML
			}
		}
	}
	
	def debugMethods = {
		switch (request.method) {
			case "POST":
				render "POST done!\n"
				break
			case "GET":
				render "GET done!\n"
				break
			case "PUT":
				render "PUT done!\n"
				break
			case "DELETE":
				render "DELETE done!\n"
				break
			default: render "No Such Method\n"
		}
	}
}
